CREATE PROCEDURE coreWFTasksSave
(
	@id						int output,
	@HandlerCodeID			nvarchar(50),
	@FK_DefinitionID		int,
	@FK_ProcessID			int,
	@FK_TaskingID			int,
	@FK_ForOperatorID		int,
	@FK_ForOperatorGroupID	int,
	@ForSystem				bit,
	@ForSystemExecDT		datetime,
	@StartDT				datetime,
	@DueDT					datetime,
	@TaskCaption			nvarchar(500),
	@DataItemText			nvarchar(1000),
	@FK_DataID				int
)
AS
BEGIN
	/* ID Will always be -1 - tasks are never edited, they are created and deleted */
	IF @id = -1
	BEGIN
		SET NOCOUNT ON;
		
		INSERT INTO WFTasks 
		( HandlerCodeID, FK_DefinitionID, FK_ProcessID, FK_TaskingID, FK_ForOperatorID, 
		  FK_ForOperatorGroupID, ForSystem, ForSystemExecDT, StartDT, DueDT, TaskCaption,
		  DataItemText, FK_DataID )
		 VALUES
		( @HandlerCodeID, @FK_DefinitionID, @FK_ProcessID, @FK_TaskingID, @FK_ForOperatorID, 
		  @FK_ForOperatorGroupID, @ForSystem, @ForSystemExecDT, @StartDT, @DueDT, @TaskCaption,
		  @DataItemText, @FK_DataID )
	
		SET NOCOUNT OFF;
		SELECT @id = @@IDENTITY;

	END
END
